package model.data.database;

import java.util.ArrayList;
import java.util.List;

public class DataRecord {
	/* A list of parameter names */
	private List<String> parameters;
	/* A list of parameter values */
	private List<String> values;
	
	/** Constructs a new database result */
	public DataRecord() {
		this.init();
	}
	
	/** Resets the database result */
	public void init() {
		this.parameters = new ArrayList<String>();
		this.values = new ArrayList<String>();
	}
	
	/** Adds a column to the record */
	public void addColumn(String parameter, String value) {
		this.parameters.add(parameter);
		this.values.add(value);
	}
	
	/** Retrieves the value for a given parameter */
	public String getValue (String parameter) {
		int index = this.parameters.indexOf(parameter);
		return this.values.get(index);
	}
	
	/** Returns a string representation of the object */
	@Override
	public String toString() {
		StringBuilder s = new StringBuilder();
		for (int i = 0; i < this.parameters.size(); i++) {
			String parameter = this.parameters.get(i);
			String value = this.values.get(i);
			s.append(String.format("%s: %s%n", parameter, value));
		}
		return s.toString();
	}
}
